package by.bsuir.chess.controllers
{
	import by.bsuir.chess.models.BoardState;
	import by.bsuir.chess.models.GameModel;
	import by.bsuir.chess.vo.Piece;

	import by.bsuir.chess.vo.Positions;

	import flash.geom.Point;

	public class GameController
	{
		[Bindable]
		private var model : GameModel = GameModel.inst;

		public function GameController(lock : SingletonLock)
		{
			initBoardState();
		}

		private function initBoardState() : void
		{
			model.boardState = BoardState.MAIN_STATE;
		}

		public function doTurn(piece : Piece, p : Point) : void
		{
			var possibleMoves : Positions = piece.getMoves();
			if (!possibleMoves.contains(p))
				throw new Error("Invalid move");
			model.boardState[p.x][p.y] = piece;
		}

		private static var _inst : GameController;

		public static function get inst() : GameController
		{
			if (!_inst)
				_inst = new GameController(new SingletonLock());
			return _inst;
		}
	}
}
class SingletonLock
{

}
